//
//  FactoryCollCell.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/8/11.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
protocol FactoryCollCellDelegate {
    func deleteCellAtIndexpath(indexPath: NSIndexPath, cellView: UIView)
    func showAllDeleteBtn(type: String)
}
class FactoryCollCell: UICollectionViewCell {
    var deleteBtn: UIButton!
    var indexPath: NSIndexPath!
    var type: String!
    var photoType = ""//1//企业执照 2企业风采
    
    @IBOutlet weak var iv: UIImageView!
    var delegate:FactoryCollCellDelegate?
    override func awakeFromNib() {
        super.awakeFromNib()
        if self.type != "1"{
            self.addDeleteButton()
            self.addLongPressGesture()
        }
        
        // Initialization code
    }
    //MARK:ADDDelegateBtn
    func addDeleteButton() {
        self.deleteBtn = UIButton(type: UIButtonType.Custom)
        self.deleteBtn.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
        deleteBtn.setImage(UIImage(named: "delete")!, forState: UIControlState.Normal)
        deleteBtn.backgroundColor = UIColor.redColor()
        self.deleteBtn.hidden = true
        deleteBtn.addTarget(self, action: #selector(self.btnClick), forControlEvents:UIControlEvents.TouchUpInside)
        self.contentView.addSubview(deleteBtn)
    }
    
    func btnClick(){
        delegate?.deleteCellAtIndexpath(indexPath, cellView: self)
    }
    
    func addLongPressGesture(){
        
        let lpgr = UILongPressGestureRecognizer(target: self, action: #selector(self.longClick))
        self.addGestureRecognizer(lpgr)
    }
    
    
    func longClick(lpgr: UILongPressGestureRecognizer) {
        if photoType == ""{
            self.delegate!.showAllDeleteBtn("")
        }
        
        self.delegate!.showAllDeleteBtn(photoType)
    }
    

}
